package com.sgcc.operate.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.common.datascope.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.operate.domain.OReport;
import com.sgcc.operate.service.IOReportService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 报告管理Controller
 * 
 * @author sgcc
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/report")
public class OReportController extends BaseController
{
    @Autowired
    private IOReportService oReportService;

    /**
     * 查询报告管理列表
     */
    //@PreAuthorize(hasPermi = "operate:report:list")
    @GetMapping("/list")
    @DataScope(deptAlias = "o2")
    public TableDataInfo list(OReport oReport)
    {
        startPage();
        List<OReport> list = oReportService.selectOReportList(oReport);
        return getDataTable(list);
    }

    /**
     * 导出报告管理列表
     */
    //@PreAuthorize(hasPermi = "operate:report:export")
    @Log(title = "报告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @DataScope(deptAlias = "o2")
    public void export(HttpServletResponse response, OReport oReport) throws IOException
    {
        List<OReport> list = oReportService.selectOReportList(oReport);
        ExcelUtil<OReport> util = new ExcelUtil<OReport>(OReport.class);
        util.exportExcel(response, list, "report");
    }

    /**
     * 获取报告管理详细信息
     */
    //@PreAuthorize(hasPermi = "operate:report:query")
    @GetMapping(value = "/{reId}")
    public AjaxResult getInfo(@PathVariable("reId") String reId)
    {
        return AjaxResult.success(oReportService.selectOReportById(reId));
    }

    /**
     * 新增报告管理
     */
    //@PreAuthorize(hasPermi = "operate:report:add")
    @Log(title = "报告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OReport oReport)
    {
        return toAjax(oReportService.insertOReport(oReport));
    }

    /**
     * 修改报告管理
     */
    //@PreAuthorize(hasPermi = "operate:report:edit")
    @Log(title = "报告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OReport oReport)
    {
        return toAjax(oReportService.updateOReport(oReport));
    }

    /**
     * 删除报告管理
     */
    //@PreAuthorize(hasPermi = "operate:report:remove")
    @Log(title = "报告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reIds}")
    public AjaxResult remove(@PathVariable String[] reIds)
    {
        return toAjax(oReportService.deleteOReportByIds(reIds));
    }
}
